const { exec } = require('child_process');
const iconv = require('iconv-lite');

let _voice_list=['1','2','3'];
let i=0;
setInterval(function(){
	let text=i++ + '别不信,人脸一致；通过闸机';
	_voice_list.push(text)
},1000)



setInterval(function(){
	if(flag){
		readArrayTospeak()
	}
},1000)

let flag=true;
function readArrayTospeak (){
	if(flag){
		if(_voice_list.length){
			console.log('b_length=',_voice_list.length)
			speakFuntion(_voice_list.shift());
			console.log('a_length=',_voice_list.length)
		}
	}
}

function speakFuntion(text){
	flag=false;
	let workerProcess=exec(`powershell.exe Add-Type -AssemblyName System.speech; $speak = New-Object System.Speech.Synthesis.SpeechSynthesizer; $speak.Rate = 1; $speak.Speak([Console]::In.ReadLine()); exit`, (err, stdout, stderr) => {
			if (err) {
				console.error(err);
				return;
			}
			console.log('workerProcess exit');
			flag=true;
			readArrayTospeak()
		})
	.stdin.end(iconv.encode(text, 'gbk'));
}